<template>
<div class="add-project-wrapper">
    <Modal :title="modalTitle"
        v-model="modalShow"
        @on-ok="save"
        @on-cancel="cancel"
        :auto-close="false"
        :mask-closable="false">
        <Form ref="form" :model="graph" :grid="1" :label-width="90" label-position="right">
            <Form-item label="元件名称">
                <Input placeholder="元件名称" clearable class="normal-input" v-model="graph.graphName"/>
            </Form-item>


            <!-- <Form-item label="指标大类">
                <Select placeholder="所属指标大类"  v-model="graph.classficationId" class="width-md pull-left m-r-10"  clearable>
                    <Option :value="item.catalogType" v-for="(item,index) in projectList" :key="index" >{{item.catalogTypeName}}</Option>
                </Select>
            </Form-item> -->
            <Form-item label="描述">
                <Input placeholder="描述" clearable type="textarea" class="normal-input-area" :rows="2" v-model="graph.remark"/>
            </Form-item>
        </Form>
    </Modal>
</div>
</template>

<script>
import util         from 'util'
import getData      from 'getData'
export default {
    data () {
        return {
            graph: {
            },
            modalShow: false,
            modalTitle: '基本信息编辑',
            projectList: [],
            lastProId: null,
        }
    },
    methods: {

        queryprojectList(){ //查询分组信息
            getData.get('projectTree').then(res =>{
                if(res.data.code != 1 ){
                    this.$set(this,"projectList",res.data.data);
                }else{
                    this.$Message.error('分组信息查询失败!');
                }
            })
        },

        cancel() {
            this.$refs.form.resetFields();
            this.modalShow = false;
        },

        //编辑保存数据
        save() {
            let that = this;
            getData.post('saveGraph',that.graph).then((res) => {
                if (res.status == 200 && res.data.code == '000') {
                    that.$Message.success('保存元件成功！');
                    that.$emit("refreshGraphList",that.lastProId);
                    that.cancel();
                } else {
                    this.$Message.error('保存元件失败！');
                }
            })
        },
        show(graph) {
            this.modalTitle = '基本信息编辑';
            this.graph = util.util.cloneObj(graph);
            this.lastProId = this.graph.classficationId;
            this.modalShow = true;
            this.queryprojectList();
        },
    }
}
</script>
